let express=require('express')
let Router=express.Router()
// 导出Router
module.exports=Router
let query=require('./db')

Router.get('/navType', async (req, res) => {
    let data = [];
    let level1 = await query(`select * from navType where level=1;`);
   
    let sql = '';
    level1.forEach( (item) => {
        data.push(item);
        sql += `select * from navType where parent_id =  ${item.id};`
    });

    let sub_list = await query(sql);

    // 把子类数据处理放入分类的sub_list中
    // sub_list = [[],[],[],[]]
    sub_list.forEach((item,index) => {
        data[index].sub_list = [...item];
    })

    res.send({
        code: 200,
        msg: '请求成',
        data,
    })
})